import CONSTANT from '@/common/constants.js';
import http from '@/common/http.js'
import XInput from 'vux/src/components/x-input/index.vue'
import Group from 'vux/src/components/group/index.vue'
import Datetime from 'vux/src/components/datetime/index.vue'
import Picker from 'vux/src/components/picker/index.vue'
import Popup from 'vux/src/components/popup/index.vue'


export default {
  name: 'query',
  components: {XInput, Group, Datetime, Picker, Popup},
  data () {
    return {
      reserveNo: ''
    }
  },
  mounted () {
    var openId = window.sessionStorage.getItem('openId')
    if (openId == null || openId == '' || openId == 'undefined') {
      var s = window.location.href
      var arr = s.split('?')
      var url = arr[1]
      var theRequest = new Object()
      var strs = url.split('&')
      for (var i = 0; i < strs.length; i++) {
        theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1])
      }
      if (theRequest.openId == null) {
        location.href = "http://qsngxm.hztangong.com/wxOAuth?appId=" + theRequest.appId + "&typeId=1"
      } else {
        var openIds = theRequest.openId.split('#/')
        window.sessionStorage.setItem('openId', openIds[0])
        window.sessionStorage.setItem('studentId', theRequest.studentId)
        window.sessionStorage.setItem('siteId', theRequest.siteId)
        window.sessionStorage.setItem('wxAvatar', theRequest.wxAvatar)
        window.sessionStorage.setItem('appId', theRequest.appId)
        window.sessionStorage.setItem('payOpen', theRequest.payOpen)
        var currentUrl = window.location.href
        var targetUrl = currentUrl.replace(/openId=/, '')
        console.log(targetUrl.replace(/studentId=/, ''))
        window.location.href = targetUrl.replace(/studentId=/, '')
        //history.pushState(null,null,currentUrl)
        //alert(window.location.href)
      }
    }
    this.siteId = window.sessionStorage.getItem('siteId')
    this.studentId = window.sessionStorage.getItem('studentId')
  },
  methods: {
    overModify () {
      var _this = this
      if (_this.reserveNo == '') {
        alert('请输入预约号！')
      } else {
        _this.$router.push({path: '/queryResult',query:{reserveNo:_this.reserveNo}})
      }
    },
    comeBack () {
      window.history.go(-1)
    }
  }
}
